﻿/*
 * Autore: Paolo Farina
 */

using System.ComponentModel;
using System.Windows;
using System.Windows.Input;

namespace RecipesManager.MainControls.ShopSubControls
{
    /// <summary>
    /// Logica di interazione per ShopAddWindow.xaml
    /// </summary>
    public partial class ShopAddWindow : Window
    {
        ShopMainPane _actualPanel=null;

        public ShopAddWindow()
        {
            InitializeComponent();
            _actualPanel=new ShopMainPane("")
                             {
                                 save_button = {IsDefault = true},
                                 canc_button = {IsCancel = true},
                                 FromAnotherWindow = true
                             };
            //workaround... since the constructor does the population of combobox... the FromAnotherWindows is not set... and the behaivorur isn't what we want
            _actualPanel.UpdateInteface("");
            shopContentPane.Content = _actualPanel;
            CommandManager.RegisterClassCommandBinding(typeof(ShopAddWindow), Savebinding);
            CommandManager.RegisterClassCommandBinding(typeof(ShopAddWindow), Closebinding);
        }

        void Save_Context()
        {
            if(!_actualPanel.Save())return;
            DialogResult = true;
            this.Close();
        }

        void Close_Context()
        {
            DialogResult = false;
            this.Close();
        }

        #region SaveCommandRegion

        CommandBinding Savebinding = new CommandBinding(ApplicationCommands.Save, CommandSaveHandler);

        static void CommandSaveHandler(object target, ExecutedRoutedEventArgs e)
        {
            ((ShopAddWindow)target).Save_Context();
        }

        #endregion

        #region CloseCommandRegion

        CommandBinding Closebinding = new CommandBinding(ApplicationCommands.Close, CommandCloseHandler);

        static void CommandCloseHandler(object target, ExecutedRoutedEventArgs e)
        {
            ((ShopAddWindow)target).Close_Context();
        }

        #endregion

        void ShopAddWindow_OnClosing(object sender, CancelEventArgs e)
        {
        }
    }
}
